<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>AJAX简单封装</h1>
    <input type="button" value="获取响应数据" onclick="get_data()">
    <script>
        function get_data() {
            AJAX({
                type:'get',
                url:'http://httpbin.org/get'
            })
        }

        function AJAX(options){
            let xhr = new XMLHttpRequest()

            xhr.open(options.type, options.url)

            xhr.send()
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    console.log(xhr.responseText)
                }
            }
        }

    </script>
</body>
</html>